var db = require('../../core/database.js');
var fs = require('fs');

/*
 * records sensor with its type. Possible types are
 * defined in core/enocean.js module.
 *
 * param data : a decoded data object
 */
function insertSensor(data) {
    //add sensor to sensor database and matches source to default enocean action
    db.storeSensor(data);
		
	if (data.desc == 'temperature') {
		//db.insertAction('enocean_'+data.id.toString(), 'stats/temperature');
	}

	fs.writeFile(__dirname + '/teachin.json', '{}', function(err) {
		    if (err) console.log(err.toString());
				else console.log('enocean -- new sensor teached-in');
		});
}

module.exports.execute = insertSensor;
